
#
#  SSFNET toplevel Makefile
#
#  'make all'   
#

RELEASE = 1.5.0

SHELL = /bin/sh  

#
# You may have to set SSFNETDIR, the top-level directory, by hand 
# if your version of Make doesn't support $(shell pwd)
#
SSFNETDIR       = $(shell pwd)
SSFNETSRC       = $(SSFNETDIR)/src
SSFNETLIB       = $(SSFNETDIR)/lib


JAVAC   = javac -classpath $(CLASSPATH):$(SSFNETSRC):$(SSFNETLIB)/ssf.jar:$(SSFNETLIB)/cernlite.jar:$(SSFNETLIB)/regexp.jar:$(SSFNETLIB)/plot.jar:$(SSFNETLIB)/plotapplication.jar
JAVA   = java -classpath $(CLASSPATH):$(SSFNETSRC):$(SSFNETLIB)/ssf.jar:$(SSFNETLIB)/cernlite.jar:$(SSFNETLIB)/regexp.jar:$(SSFNETLIB)/plot.jar:$(SSFNETLIB)/plotapplication.jar


#----------------------------------------------------------- MAKE ALL

all: ssf.jar cernlite.jar .common classes jar ssfdoc tests

#----------------------------------------------------------- SSFDOC

ssfdoc:
	(cd doc/ssfnet; make all)

#----------------------------------------------------------- SSF.JAR 

ssf.jar:
	@if [ X = X$(SSFNETDIR) ] ; then \
           echo \*\* Your version of Make doesn\'t support \'shell pwd\' ;\
           echo \*\* Please edit the Makefile and set SSFNETDIR by hand. ;\
	   exit 1; \
	fi
	@if test -f lib/ssf.jar; then echo ; else \
	  echo \*\* You must download and install ssf.jar ;\
	  echo \*\* in the \'lib\' directory before using SSFNET. ; \
	  false; \
	fi

#----------------------------------------------------------- CERNLITE.JAR 

cernlite.jar:
	@if test -f lib/cernlite.jar; then echo ; else \
	  (cd src ; ./.jmake ../lib/cernlite.jar) ; \
	fi

#----------------------------------------------------------- MAKEFILE.COMMON 

.common:
	@-if test -f Makefile.common ; \
	  then mv Makefile.common Makefile.common.bak; fi
	@-touch Makefile.common 
	@-echo \# installation path info for SSFNET \ >> Makefile.common
	@-echo >> Makefile.common
	@-echo SSFNETDIR = `pwd` >> Makefile.common
	@-echo SSFNET_TEST_CLASSPATH = $$\(CLASSPATH\):$$\(SSFNETDIR\)/src:$$\(SSFNETDIR\)/lib/ssfnet.jar:$$\(SSFNETDIR\)/lib/ssf.jar:$$\(SSFNETDIR\)/lib/cernlite.jar:$$\(SSFNETDIR\)/lib/regexp.jar:$$\(SSFNETDIR\)/lib/plot.jar:$$\(SSFNETDIR\)/lib/plotapplication.jar >> Makefile.common
	@touch .common


# ----------------------------------------------------------- MAKE TESTS

tests:	.common
	@echo ''
	@echo '                  RUNNING VALIDATION TESTS...'
	@echo ''
	(cd src/SSF/OS/TCP/test ; make tests)
	(cd src/SSF/OS/UDP/test ; make test)
	(cd src/SSF/OS/WWW/test ; make)
	(cd src/SSF/OS/OSPF     ; make valid)
	(cd src/SSF/OS/OSPFv2/test ; make tests)
	(cd src/SSF/OS/BGP4     ; make valid)
	(cd src/SSF/App/Worm    ; make tests)
	@echo
	@echo TESTING COMPLETED.  See "examples" directory for more.

#----------------------------------------------------------- MAKE CLASSES

classes: SSF.OS \
         SSF.Util.Plot \
         SSF.Util.Random \
         SSF.Net.Util \
         SSF.Net \
         SSF.Util.Streams \
         SSF.OS.TCP \
         SSF.OS.UDP \
         SSF.OS.Socket \
         SSF.OS.WWW \
         SSF.OS.BGP4 \
         SSF.OS.OSPF \
         SSF.OS.OSPFv2 \
         SSF.OS.NetFlow \
         SSF.App.DDoS \
         SSF.App.Worm

SSF.App.DDoS:
	@if test ! -d src/SSF/App/DDoS; \
	then (echo 'directory src/SSF/App/DDoS/ does not exist'; exit 1); fi
	(cd src/SSF/App/DDoS; $(MAKE))

SSF.App.Worm:
	@if test ! -d src/SSF/App/Worm; \
	then (echo 'directory src/SSF/App/Worm/ does not exist'; exit 1); fi
	(cd src/SSF/App/Worm; $(MAKE))

SSF.OS:
	(cd src/SSF/OS; $(JAVAC) *.java);

SSF.OS.BGP4:
	@if test ! -d src/SSF/OS/BGP4; \
	then (echo 'directory src/SSF/OS/BGP4/ does not exist'; exit 1); fi
	(cd src/SSF/OS/BGP4; $(MAKE) all)

SSF.OS.OSPFv2:
	@if test ! -d src/SSF/OS/OSPFv2; \
	then (echo 'directory src/SSF/OS/OSPFv2/ does not exist'; exit 1); fi
	(cd src/SSF/OS/OSPFv2; $(MAKE) all)

SSF.OS.OSPF:
	@if test ! -d src/SSF/OS/OSPF; \
	then (echo 'directory src/SSF/OS/OSPF/ does not exist'; exit 1); fi
	(cd src/SSF/OS/OSPF; $(MAKE) all)

SSF.OS.TCP:
	@if test ! -d src/SSF/OS/TCP; \
	then (echo 'directory src/SSF/OS/TCP/ does not exist'; exit 1); fi
	(cd src/SSF/OS/TCP;  $(MAKE) tcp)

SSF.OS.UDP:
	@if test ! -d src/SSF/OS/UDP; \
	then (echo 'directory src/SSF/OS/UDP/ does not exist'; exit 1); fi
	(cd src/SSF/OS/UDP; $(MAKE) udp)

SSF.OS.NetFlow:
	@if test ! -d src/SSF/OS/NetFlow; \
	then (echo 'directory src/SSF/OS/NetFlow/ does not exist'; exit 1); fi
	(cd src/SSF/OS/NetFlow; $(MAKE))

SSF.OS.Socket:
	@if test ! -d src/SSF/OS/Socket; \
	then (echo 'directory src/SSF/OS/Socket/ does not exist'; exit 1); fi
	(cd src/SSF/OS/Socket; $(MAKE) socket)

SSF.OS.SNMP:
	@if test ! -d src/SSF/OS/SNMP; \
	then (echo 'directory src/SSF/OS/SNMP/ does not exist'; exit 1); fi
	(cd src/SSF/OS/SNMP; $(MAKE) classes)

SSF.OS.WWW:
	@if test ! -d src/SSF/OS/WWW; \
	then (echo 'directory src/SSF/OS/WWW/ does not exist'; exit 1); fi
	(cd src/SSF/OS/WWW;  $(JAVAC) *.java)

SSF.Util.Streams:
	(cd src/SSF/Util/Streams ; $(JAVAC) *.java)

SSF.Util.Random:
	(cd src/SSF/Util/Random ; $(JAVAC) *.java)

SSF.Util.Plot:
	(cd src/SSF/Util/Plot ; $(JAVAC) *.java)

SSF.Net.Util:
	(cd src/SSF/Net/Util; $(JAVAC) *.java)

SSF.Net:
	(cd src/SSF/Net; $(JAVAC) *.java)

#----------------------------------------------------------- CHANGE PACKAGES 

#
# Raceway IDE -- must have {lib/ssf.jar}->lib/raceway.jar 
#
# (Default in SSFNet v1.1)
#
use-raceway:
	- find . -name '*.java' -exec $(SSFNETDIR)/change-package.sh {} \
		com.cooperate.SSF com.renesys.raceway.SSF \;
	- find . -name '*.java' -exec $(SSFNETDIR)/change-package.sh {} \
		SSF.DML com.renesys.raceway.DML \; 
	- make clean
	- rm -f lib/ssfnet.jar
	@echo Conversion complete -- \"make all\" to rebuild the system. 

#
# JSSF IDE -- must have lib/ssf.jar->lib/jssf.jar and lib/dml.jar
#
# (Default in SSFNet v1.0)
#
use-jssf:
	- find src -name '*.java' -exec $(SSFNETDIR)/change-package.sh {} \
	        com.renesys.raceway.SSF com.cooperate.SSF \; 
	- find src -name '*.java' -exec $(SSFNETDIR)/change-package.sh {} \
		com.renesys.raceway.DML SSF.DML \; 
	- make clean
	- rm -f lib/ssfnet.jar
	@echo Conversion complete -- \"make all\" to rebuild the system. 

#----------------------------------------------------------- MAKE JAR

jar:
	(cd src; jar cvf ../lib/ssfnet.jar \
		SSF/OS/*.class \
		SSF/OS/TCP/*.class \
		SSF/OS/TCP/test/*.class \
		SSF/OS/UDP/*.class \
		SSF/OS/UDP/test/*.class \
		SSF/OS/Socket/*.class \
		SSF/OS/WWW/*.class \
		SSF/OS/BGP4/*.class SSF/OS/BGP4/Util/*.class \
		SSF/OS/BGP4/Comm/*.class SSF/OS/BGP4/Path/*.class \
		SSF/OS/BGP4/Policy/*.class SSF/OS/BGP4/Timing/*.class \
		SSF/OS/BGP4/Players/*.class SSF/OS/BGP4/Widgets/*.class \
		SSF/OS/OSPF/*.class \
		SSF/OS/OSPFv2/*.class \
		SSF/OS/NetFlow/*.class \
		SSF/OS/NetFlow/Filter/*.class \
		SSF/OS/NetFlow/Util/*.class \
		SSF/Util/Random/*.class \
		SSF/Util/Plot/*.class \
		SSF/Util/Streams/*.class \
		SSF/Net/*.class \
		SSF/Net/Util/*.class \
		SSF/App/DDoS/*.class \
		SSF/App/Worm/*.class) 

#----------------------------------------------------------- MAKE CLEAN

clean:	.common
	- (cd src/SSF/OS/OSPF ; make spotless)
	- (cd src/SSF/OS/OSPFv2 ; make clean)
	- (cd src/SSF/OS/BGP4 ; make spotless)
	- (cd src/SSF/OS/TCP ; make clean)
	- (cd src/SSF/OS/UDP ; make clean)
	- (cd src/SSF/OS/WWW ; make clean)
	- (cd src/SSF/OS/NetFlow ; make clean)
	- (cd src/SSF/Util/Streams/example ; make clean)
	- (cd src/SSF/Util/Plot ; make clean)
	- (cd src/SSF/App/DDoS; make clean)
	- (cd src/SSF/App/Worm; make clean)
	- rm -f .common 
	- (cd examples ; make clean)
	- find src/ -name '#*#' -exec rm -f {} \; -print
	- find src/ -name '*.class' -exec rm -f {} \; -print
	- (cd doc/ssfnet ; make spotless)
	- rm -f Makefile.common Makefile.common.bak

distclean: clean
	- rm -f Makefile.common Makefile.bak


spotless:  clean .common
	- rm -f lib/ssfnet.jar
	- rm -f lib/cernlite.jar
	- rm -f Makefile.common
